package com.wangdao.wechatmall.controller.admin;

import com.wangdao.wechatmall.bean.vo.admin.*;
import com.wangdao.wechatmall.service.admin.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ConfigController
 * created by feng on 7/9/21
 */
@RestController
@RequestMapping("admin/config")
//http://localhost:8083/admin/config/express
public class ConfigController {

    @Autowired
    ConfigService configService;

    @GetMapping("express")
    public BaseRespVo express() {
        ExpressVO express = configService.expressGet();
        return BaseRespVo.ok(express);
    }

    //http://localhost:8083/admin/config/express
    @PostMapping("express")
    public BaseRespVo express(@RequestBody ExpressVO expressVo) {
        Integer affectedRow = configService.expressPost(expressVo);
        if (affectedRow == 2) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }

    //http://localhost:8083/admin/config/order
    @GetMapping("order")
    public BaseRespVo order() {
        ConfigOrderVO configOrderVO = configService.orderGet();
        return BaseRespVo.ok(configOrderVO);
    }

    //http://localhost:8083/admin/config/order
    @PostMapping("order")
    public BaseRespVo order(@RequestBody ConfigOrderVO configOrderVO) {
        Integer affectedRow = configService.orderPost(configOrderVO);
        if(affectedRow == 3){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }

    //http://localhost:8083/admin/config/wx
    @GetMapping("wx")
    public BaseRespVo wxGet() {
        ConfigWxVO configWxVO = configService.wxGet();
        return BaseRespVo.ok(configWxVO);
    }

    //http://localhost:8083/admin/config/wx
    @PostMapping("wx")
    public BaseRespVo wxPost(@RequestBody ConfigWxVO configWxVO) {
        Integer affectedRow = configService.wxPost(configWxVO);
        System.out.println(affectedRow);
        if (affectedRow == 7) {
            return BaseRespVo.ok();
        }

        return BaseRespVo.fail();
    }

    //http://localhost:8083/admin/config/mall
    @GetMapping("mall")
    public BaseRespVo mall() {
        ConfigMallVO configMallVO = configService.mallGet();
        return BaseRespVo.ok(configMallVO);
    }

    //http://localhost:8083/admin/config/mall
    @PostMapping("mall")
    public BaseRespVo mall(@RequestBody ConfigMallVO configMallVO) {
        int affectedRow = configService.mallPost(configMallVO);

        if (affectedRow == 4) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }
}